import { Component } from '@angular/core';
import { NavController, NavParams,ViewController  } from 'ionic-angular';
import { MistakeService } from '../mistake.service';

@Component({
  selector: 'page-substitute-question',
  templateUrl: 'substitute-question.html',
  providers:[MistakeService],
})
export class SubstituteQuestionPage{
    substituteQuesList :any;
    questionUid:any;
    searchByTextFlag:boolean;
    searchByText:string;
    contentFlag:boolean;
    constructor(
      public navCtrl: NavController,
      public navParams: NavParams,
      public viewCtrl:ViewController,
      public mistakeService:MistakeService
     ){
       this.searchByText = "";
       this.substituteQuesList = [];
       this.contentFlag = true;
       this.substituteQuesList = this.navParams.get("substituteQuesList");
       this.searchByTextFlag = this.navParams.get("searchByTextFlag");
    }


    searchQuesByText(){

      this.mistakeService.substituteByText(this.searchByText).then(
        data=>(
          this.substituteQuesList = data,
          //this.substituteQuesList = this.substituteQuesList,
          console.log("data:" + data)
        )
      ).catch(error=>console.log(error));
    }

    close(){

    this.viewCtrl.dismiss("");

    }

    substitute(questionUid){
      this.viewCtrl.dismiss(questionUid);
    }

    changeFlag(){
      if(this.contentFlag == false){
        this.contentFlag = true;
      }else if(this.contentFlag == true){
        this.contentFlag = false;
      }else{
        this.contentFlag = true;
      }

    }

}
